﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class Users_updateprofile : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ProfileCommon p = Profile.GetProfile(Membership.GetUser().UserName);
            txtFirstName.Text = p.FirstName;
            txtLastName.Text = p.LastName;
            txtAge.Text = p.Age.ToString();
            txtAddress.Text = p.Address;
            txtPhoneNumber.Text = p.PhoneNumber.ToString();
            txtCreditCard.Text = p.CreditCard.ToString();
            if (p.Male)
            {
                RadioButton1.Checked = true;
                RadioButton2.Checked = false;
            }
            else
            {
                RadioButton1.Checked = false;
                RadioButton2.Checked = true;

            } 
        }
    }

    protected void btnUpdate_Click1(object sender, EventArgs e)
    {
        string _fname = txtFirstName.Text;
        string _lname = txtLastName.Text;
        int _age = Convert.ToInt32(txtAge.Text);
        string _address = txtAddress.Text;
        long _phoneNumber = Convert.ToInt64(txtPhoneNumber.Text);
        long _creditcard = Convert.ToInt64(txtCreditCard.Text);

        ProfileCommon p = Profile.GetProfile(Membership.GetUser().UserName);
        p.FirstName = _fname;
        p.LastName = _lname;
        p.Age = _age;
        p.Address = _address;
        p.PhoneNumber = _phoneNumber;
        p.CreditCard = _creditcard;
        p.Male = RadioButton1.Checked;

        p.Save();
        Response.Redirect("~/Users/UserProfile.aspx");
    }


    protected void button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Users/UserProfile.aspx");
    }

}
